import 'package:flutter/material.dart';
import 'package:flutter_baselib/lib.dart';

///@date:  2021/3/1 11:05
///@author:  lixu
///@description: ViewModel 基类
///进入View页面时，直接显示UI（不需要请求http获取数据）的场景继承[BaseCommonViewModel]类
abstract class BaseCommonViewModel with ChangeNotifier {
  ///是否已经调用了dispose()方法
  bool _isDispose = false;

  ///是否正在请求中
  bool isLoading = false;

  ///网络请求对象，充当MVVM的Model层
  XApi api = XApi();

  ///获取tag,用于日志tag
  String getTag();

  ///刷新页面
  update() {
    LogUtils.v(getTag(), 'update() _isDispose:$_isDispose');
    if (!_isDispose) {
      notifyListeners();
    }
  }

  bool get isDispose => _isDispose;

  ///页面关闭时回调该方式，释放资源
  @override
  void dispose() {
    super.dispose();
    _isDispose = true;
    LogUtils.v(getTag(), 'dispose()');
  }
}
